package org.standard.tianjieci.action;

import java.util.Date;
import java.util.List;

import org.standard.base.model.BaseRole;
import org.standard.base.model.BaseUser;
import org.standard.commons.service.Service;
import org.standard.commons.struts2.BaseAction;
import org.standard.commons.utils.Constants;
import org.standard.commons.utils.Utils;
import org.standard.tianjieci.model.Tianjieci;

import com.googlecode.jsonplugin.annotations.JSON;

public class TianjieciAction extends BaseAction{

	private Tianjieci tianjieci;
	private BaseUser user;
	private BaseRole role;
	private Service service;
	
	public String index(){
		
		List list = service.findPOJOList("from Tianjieci");
		if (list != null && !list.isEmpty()) {
			tianjieci = (Tianjieci) list.get(0);
		}
		return MODIFY;
	}
	
	public String findJieciJson(){
		
		index();
		List list = service.findPOJOListBySql("select count(*) from Proposal " +
				"where proposal_Session = '"+tianjieci.getProposalSession()+"' " +
						"and proposal_Count = '"+tianjieci.getProposalCount()+"'");
		tianjieci.setSum(String.valueOf(list.get(0)));
		return JSON;
	}
	
	public String modify() {
		
		if (tianjieci != null) {
			tianjieci.setDate(new Date());
			user = (BaseUser) session.get(Constants.SESSION_USER);
			tianjieci.setUserName(user.getUserName());
			if (!Utils.isStringNull(tianjieci.getId())) {
				service.modifyPOJO(tianjieci);
			} else {
				service.createPOJO(tianjieci);
			}
		}
		return MODIFY;
	}
	@JSON(name="tianjieci")
	public Tianjieci getTianjieci() {
		return tianjieci;
	}

	public void setTianjieci(Tianjieci tianjieci) {
		this.tianjieci = tianjieci;
	}

	public BaseUser getUser() {
		return user;
	}

	public void setUser(BaseUser user) {
		this.user = user;
	}

	public BaseRole getRole() {
		return role;
	}

	public void setRole(BaseRole role) {
		this.role = role;
	}

	public Service getService() {
		return service;
	}

	public void setService(Service service) {
		this.service = service;
	}
	
	
	
}
